package com.shengwei.truck.driver.view.ui.task;

import android.content.Intent;
import android.os.Bundle;
import androidx.lifecycle.ViewModel;
import com.shengwei.truck.driver.R;
import com.shengwei.truck.driver.bean.FileUrlBean;
import com.shengwei.truck.driver.databinding.ActivityPhotoGallyBinding;
import com.shengwei.truck.driver.utils.IntentConstants;
import com.shengwei.truck.driver.view.adapter.task.PhotoPagerAdapter;
import com.shengwei.truck.driver.view.ui.BaseActivity;

import java.util.List;

public class PhotoGallyActivity extends BaseActivity<ViewModel, ActivityPhotoGallyBinding> {

    private int mCurPosition;
    private List<FileUrlBean> mDataList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getLastIntent();
        initView();
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_photo_gally;
    }


    /**
     * 获取上一页传递过来的数据
     */
    private void getLastIntent(){
        Intent intent = getIntent();
        Bundle b = intent.getExtras();
        if(b != null){
            mCurPosition = b.getInt(IntentConstants.EXTRA_CURRENT_IMG_POSITION);
            mDataList = (List<FileUrlBean>) b.getSerializable(IntentConstants.EXTRA_IMAGE_LIST);
        }
        return;
    }

    /**
     * 初始化控件
     */
    public void initView() {
        PhotoPagerAdapter photoPagerAdapter = new PhotoPagerAdapter(this,this.getSupportFragmentManager(),mDataList);
        mDataBinding.viewPager.setAdapter(photoPagerAdapter);
        mDataBinding.viewPager.setCurrentItem(mCurPosition);
    }
}